
/**
 * Created by XGJ on 2017/9/21.
 */

import {Component} from "@angular/core";
import {NavController, NavParams} from "ionic-angular";
import {NativeServiceC} from "../../../providers/NativeServiceC";
import {HttpService} from "../../../providers/HttpService";
@Component({
    selector: 'page-classifyDetail',
    templateUrl: 'classifyDetail.html'
})
export class ClassifyDetailPage{
    title:string;
    typeId:number;
    type:string;
    items:Object[];

    constructor(
        private navCtrl:NavController,
        private nativeService:NativeServiceC,
        private httpService:HttpService,
        private navParams:NavParams)
    {
        this.title = navParams.get("title");
        this.typeId = navParams.get("id");
        this.type = navParams.get("type");
    }


    ionViewDidLoad(){
        this.getItems();
    }

    homeCellClick(index){
        console.log("cell组件通讯",index);
    }
    homeLikeClick(index){
        console.log("cell组件通讯",index);
    }

    private getItems(){
        let url,key;
        if(this.typeId === 0){
            url = '/v1/collections';
            key = 'collections'
        }else if(this.type === 'collections'){
            url = '/v1/collections/' + this.typeId +'/posts';
            key = 'posts'
        }else{
            url = '/v1/channels/' + this.typeId +'/items';
            key = 'items'
        }
        let sender={
            limit: 20,
            offset: 0,
        }
        this.httpService.get(url,sender).subscribe(res=>{
            console.log(res);
            this.nativeService.hideLoading();
            this.items=res[key];
            console.log(this.items);
        })

    }



}